//数青蛙
//测试链接 https://leetcode.cn/problems/minimum-number-of-frogs-croaking/
public class MinNumberOfFrogs {
    public int minNumberOfFrogs(String croakOfFrogs) {
        int[] map = new int[5];
        int len = croakOfFrogs.length();

        for(int i = 0; i < len; i++){
            char ch = croakOfFrogs.charAt(i);
            if(ch == 'c'){
                //先判断k中是否有数
                if(map[4] != 0)  map[4]--;
                map[0]++;
            }else{
                if(ch =='r'){
                    if(map[0] == 0){
                        return -1;
                    }
                    map[0]--;
                    map[1]++;
                }else if(ch =='o'){
                    if(map[1] == 0){
                        return -1;
                    }
                    map[1]--;
                    map[2]++;
                }else if(ch =='a'){
                    if(map[2] == 0){
                        return -1;
                    }
                    map[2]--;
                    map[3]++;
                }else if(ch =='k'){
                    if(map[3] == 0){
                        return -1;
                    }
                    map[3]--;
                    map[4]++;
                }
            }
        }

        for(int i = 0; i < 4; i++){
            if(map[i] != 0){
                return -1;
            }
        }
        return map[4];
    }
}
